package com.yt.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
@RefreshScope
public class TestController {
    @Value("${nickname}")
    String nickname;

    @Resource
    RestTemplate restTemplate;
    @RequestMapping("/getport")
    public String getPort(){
        String message=null;
        String url="http://nacos-provider";
        ResponseEntity<String> re= restTemplate.getForEntity(url+"/getport/",String.class);
        log.info(re.getStatusCode().toString());
        if(re.getStatusCode().is2xxSuccessful()){
            log.info("读取成功");
            message=re.getBody();
        }else{
            message="访问失败";
        }
        return nickname+"-80:"+message;
    }
}
